// Application of data structure
// Created by Administrator on 2025/6/11.
//

#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
using namespace std;

/**
 * array
 */
void arrayFunc() {
    string names[] = {"小明", "小红", "小白"};
    for (string name: names) {
        cout << name << "\t";
    }
    cout << endl;
}

struct Book {
    int id;
    string title;
    string author;

    Book(int id, string title, string author): id(id), title(title), author(author) {
        cout << "create Book Constructor end" << endl;
    }
};

/**
 * Struct
 */
void structFunc() {
    Book book(1, "《算法导论》", "R.L.D. Tarjan");
    cout << book.id << "\t" << book.title << "\t" << book.author << endl;
}

class Student {
    int id;
    string name;
    int age;
    int sex;

public:
    Student(int id, string name, int age, int sex): id(id), name(name), age(age), sex(sex) {
    };

    void printInfo() {
        cout << id << "\t" << name << "\t" << age << "\t" << sex << endl;
    }
};

/**
 * Class
 */
void classFunc() {
    Student student(1, "小王", 18, 1);
    student.printInfo();
}

/**
 * Stack
 * First input Last output
 */
void stackFunc() {
    stack<int> s;
    s.push(10);
    for (int i = 0; i < 5; i++) {
        s.push(i);
    }
    s.push(999); // last input
    cout << "s of first value is ：" << s.top() << endl; // output top value : 999
    s.pop(); // delete top value
    cout << "s of first value is ：" << s.top() << endl; // output top value : 4
}

/**
 * queue
 * First input first output
 */
void queueFunc() {
    queue<int> q;
    for (int i = 0; i < 10; i++) {
        q.push(i);
    }
    cout << "queue of first value is ：" << q.front() << endl; // output first value : 0
    q.pop(); // delete first value
    cout << "queue of first value is ：" << q.front() << endl; // output 1
}

/**
 * Deque
 * two_way input
 */
void dequeFunc() {
    deque<int> dq;
    dq.push_front(2); // first input 2
    dq.push_back(5); // last inout 5
    dq.push_front(1); // overwrite first

    cout << "dq first value is:" << dq.front() << endl;
    cout << "dq last value is:" << dq.back() << endl;
}

/**
 * hash table
 */
void hashTableFunc() {
    unordered_map<int, string> hashTable;
    hashTable[1] = "小明"; // key = 1 ,value = 小明
    hashTable[2] = "小白";
    hashTable[1] = "小绿"; // overwrite 小明
    hashTable[3] = "小蓝";

    cout << "hash table key 1 of value is :" << hashTable.at(1) << endl;
    cout << "hash table key 2 of value is :" << hashTable[2] << endl;
    cout << "hash table size is:" << hashTable.size() << endl;
}

/**
 * map
 */
void mapFunc() {
    map<int, string> studentMap;
    studentMap[1001] = "小黄";
    studentMap[1002] = "小凯";
    studentMap[1003] = "小白";

    cout << "id is 1001 of name is: " << studentMap[1001] << endl;
    cout << "id is 1003 of name is: " << studentMap.at(1003) << endl;
}

/**
 * set
 * unique value
 */
void setFunc() {
    set<int> s;
    s.insert(1);
    s.insert(1);
    s.insert(2);
    s.insert(3);
    s.insert(3);

    for (int i: s) {
        cout << i << "\t";
    }
    cout << endl;
}

/**
 * vector
 */
void vectorFunc() {
    vector<int> v;
    v.push_back(1); // push value to last
    v.push_back(2);
    v.push_back(3);
    v.pop_back(); // delete last value
    for (int v1: v) {
        cout << v1 << "\t";
    }
    cout << endl;
}

int main(int argc, char *argv[]) {
    // structFunc();
    // classFunc();
    // stackFunc();
    // queueFunc();
    // dequeFunc();
    // hashTableFunc();
    // mapFunc();
    // setFunc();
    vectorFunc();
}
